﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">
    $(function() {
        var options = {
            slide_all: false
        };

        $("#wflist #apply_accordion").selfAccordion(options);
        tableSelectOrder("#wflist .table_style");
    })

    function checkProcedure(wftemplate_id, areaid) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoGetWFChart",
            data: { "wftemplate_id": wftemplate_id },
            success: function(data) {
                addtab(areaid + "-check", "审批流程图");
                var workarea = $("#workarea-" + areaid + "-check").html("<div id='procedure'></div>");
                var procedure = $(workarea).children("#procedure");
                var drag = $.fn.Procedure({ renderTo: procedure, inititedata: data });
            }
        });
    }

    // 发起员工转正
    function turntoformal(wf_id, user_id, areaid) {
        $.ajax({
            type: "POST",
            url: "/TmpUsr/WFStart",
            data: { "wf_id": wf_id, "user_id": user_id },
            success: function(data) {
                addtab('" + areaid + "-sponsor', '发起申请单');
                $("#workarea-" + areaid + "-sponsor").html(data);
            }
        })
    }

    // 发起申请单
    function applyform(wf_id, user_id, areaid) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/WFStart",
            data: { "wf_id": wf_id, "user_id": user_id, "areaid": areaid },
            success: function(data) {
                addtab(areaid + "-sponsor", '发起申请单');
                $("#workarea-" + areaid + "-sponsor").html(data);
            }
        })
    }

    // 修改权限
    function changepower(wf_id) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/WFMrg",
            data: { "wf_id": wf_id },
            success: function(data) {
                addtab('2-1-1', '流程管理');
                $("#workarea-2-1-1").html(data);
            }
        })
    }
</script>

<div id="wflist" style="padding-top: 35px;">
    <div id="apply_accordion">
        <%
            using (System.Data.DataTable dt_wftype = ViewData["dt_wftype"] as System.Data.DataTable)
            {
                for (int j = 0; j < dt_wftype.Rows.Count; j++)
                {
        %>
        <div>
            <h3>
                <a href="#">
                    <%=dt_wftype.Rows[j]["名称"]%></a></h3>
            <div>
                <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
                    <thead>
                        <tr>
                            <th class="th_long">
                                申请单名称
                            </th>
                            <th class="th_middle">
                                创建时间
                            </th>
                            <th class="th_short">
                                创建人
                            </th>
                            <th>
                                备注
                            </th>
                            <th class="th_middle">
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <%
                            var areaid = ViewData["area_id"] as String;
                            if (String.IsNullOrEmpty(areaid))
                                areaid = "2-1";

                            System.Data.DataTable dt_wf = ViewData["dt_wf"] as System.Data.DataTable;
                            var tmp_drs = dt_wf.Select("类型编码='" + dt_wftype.Rows[j]["编码"].ToString() + "'");
                            if (tmp_drs == null || tmp_drs.Count() == 0)
                            {%>
                        <tr>
                            <td colspan="0" style="text-align: center;">
                                当前无数据！
                            </td>
                        </tr>
                        <% }
                            else
                            {
                                for (int i = 0; i < tmp_drs.Count(); i++)
                                {
                        %>
                        <tr>
                            <td>
                                <%=tmp_drs[i]["名称"]%>
                            </td>
                            <td>
                                <%=DateTime.Parse(tmp_drs[i]["创建时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                            </td>
                            <td>
                                <%=tmp_drs[i]["创建人"]%>
                            </td>
                            <td>
                            </td>
                            <td>
                                <%if (ViewData["isadmin"].ToString() == "false")
                                  { %>
                                <%if (dt_wftype.Rows[j]["名称"] == "人力资源" && tmp_drs[i]["名称"] == "员工转正评价表")
                                  { %>
                                <a class="a_start" onclick="turntoformal('<%=tmp_drs[i]["编码"] %>','<%=ViewData["user_id"] %>','<%=areaid %>')">
                                    发起</a>
                                <%}
                                  else
                                  { %>
                                <a class="a_start" onclick="applyform('<%= tmp_drs[i]["编码"] %>','<%=ViewData["user_id"] %>','<%=areaid %>')">
                                    发起</a>
                                <%} %>
                                |&nbsp<%--<%=Ajax.ActionLink("查看", "WFPlateShow", new { wftemplate_id = tmp_drs[i]["模板编码"] }, new AjaxOptions { UpdateTargetId = "workarea-" + areaid + "-check", OnSuccess = "addtab('" + areaid + "-check','审批流程图')" }, new { @class = "a_lookfor" })%>--%>
                                <a class='a_lookfor' onclick="checkProcedure('<%=tmp_drs[i]["模板编码"] %>','<%=areaid %>')">
                                    查看</a>
                                <%}
                                  else
                                  {%>
                                <a onclick="changepower(<%=tmp_drs[i]["编码"] %>)">修改</a>
                                <%} %>
                            </td>
                        </tr>
                        <%
                            }
                            }
                        %>
                    </tbody>
                </table>
            </div>
        </div>
        <%}
            } %>
    </div>
</div>
